package com.notepad.pages;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class ColorView extends View{
	
	private int radiu = 5;
	private int width = 30;
	private int height = 44;
	private int defaultColor = Color.BLACK;
	private Paint mPaint;
	
	private OnColorViewClickListener listener;

	public ColorView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		initPaint();
	}

	public ColorView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		initPaint();
	}

	public ColorView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initPaint();
	}
	
	public void setShowColor(int color){
		defaultColor = color;
		invalidate();
	}
	
	public void setOnColorViewClickListener(OnColorViewClickListener ls){
		listener = ls;
	}
	
	private void initPaint(){
		mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		mPaint.setTextAlign(Paint.Align.CENTER);
		mPaint.setTextSize(12);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		mPaint.setColor(defaultColor);
		//左上角
		canvas.drawCircle(5, 5, radiu, mPaint);
		//左下角
		canvas.drawCircle(5, height - 5, radiu, mPaint);
		//右上角
		canvas.drawCircle(width - 5, 5, radiu, mPaint);
		//右下角
		canvas.drawCircle(width - 5, height - 5, radiu, mPaint);
		//矩形
		canvas.drawRect(5,0,width -5,5,mPaint);
		canvas.drawRect(5,height-5,width -5,height,mPaint);
		canvas.drawRect(0,5,5,height-5,mPaint);
		canvas.drawRect(width-5,5,width,height-5,mPaint);
		canvas.drawRect(5, 5, width-5, height-5, mPaint);
	}
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		setMeasuredDimension(30, 44);
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(listener != null){
			listener.onClick(defaultColor);
		}
		return true;
	}
}
